home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / misc / math / MathFX_src.lha / fxzbx.c < prev    next >
C/C++ Source or Header  |  1995-12-20  |  4KB  |  146 lines

  1. /* This draws a vertical line from (wx,wy1) to (wx,wy2)           */
  2. /*  which represents the vertical axis of a 3-d graph with data   */
  3. /*  values from "vmin" to "vmax". Depending on "opt", ticks and/or*/
  4. /*  subticks are placed on the line at major tick interval "tick" */
  5. /*  with "nsub" subticks between major ticks. If "tick" and/or    */
  6. /*  "nsub" is zero, automatic tick positions are computed         */
  7.  
  8. /* B: Draws left-hand axis*/
  9. /* C: Draws right-hand axis*/
  10. /* I: Inverts tick marks (i.e. drawn to the left)  */
  11. /* L: Logarithmic axes, major ticks at decades, minor ticks at units*/
  12. /* M: Write numeric label on right axis*/
  13. /* N: Write numeric label on left axis*/
  14. /* S: Draw minor tick marks  */
  15. /* T: Draw major tick marks  */
  16. /* U: Writes left-hand label*/
  17. /* V: Writes right-hand label*/
  18.  
  19. #include "mathfx.h"
  20. #include <stdio.h>
  21. #include <math.h>
  22.  
  23. #define betw(c,a,b) ((a <= c && c <= b) || (b <= c && c <= a))
  24.  
  25. static float xlog[8] =
  26.   {0.301030,0.477121,0.602060,0.698970,0.778151,0.845098,
  27.    0.903090,0.954243};
  28.  
  29. void fxzbx(opt,label,right,dx,dy,wx,wy1,wy2,vmin,vmax,tick,nsub)
  30. char *opt, *label;
  31. float dx, dy, wx, wy1, wy2, vmin, vmax, tick;
  32. int nsub, right;
  33. {
  34.       char string[40];
  35.       int lb,lc,li,ll,lm,ln,ls,lt,lu,lv;
  36.       int i, mode, prec;
  37.       int nsub1;
  38.       float xpmm, ypmm, defmaj, defmin, tick1;
  39.       float pos, tn, tp, temp;
  40.       float dwy, lambda, diag, major, minor, xmajor, xminor;
  41.       float ymajor, yminor, dxm, dym, xscl, xoff, yscl, yoff;
  42.                
  43.       dwy = wy2 - wy1;
  44.  
  45. /* Tick and subtick sizes in device coords */
  46.  
  47.       gpixmm(&xpmm,&ypmm);
  48.       gmaj(&defmaj,&major);
  49.       gmin(&defmin,&minor);
  50.       
  51.       tick1=tick;
  52.       nsub1=nsub;
  53.  
  54.       lb=strpos(opt,'B') != -1 || strpos(opt,'b') != -1;
  55.       lc=strpos(opt,'C') != -1 || strpos(opt,'c') != -1;
  56.       li=strpos(opt,'I') != -1 || strpos(opt,'i') != -1;
  57.       ll=strpos(opt,'L') != -1 || strpos(opt,'l') != -1;
  58.       lm=strpos(opt,'M') != -1 || strpos(opt,'m') != -1;
  59.       ln=strpos(opt,'N') != -1 || strpos(opt,'n') != -1;
  60.       ls=strpos(opt,'S') != -1 || strpos(opt,'s') != -1;
  61.       lt=strpos(opt,'T') != -1 || strpos(opt,'t') != -1;
  62.       lu=strpos(opt,'U') != -1 || strpos(opt,'u') != -1;
  63.       lv=strpos(opt,'V') != -1 || strpos(opt,'v') != -1;
  64.  
  65.       if (lu && !right) fxztx("h",dx,dy,wx,wy1,wy2,5.0,0.5,0.5,label);
  66.       if (lv && right) fxztx("h",dx,dy,wx,wy1,wy2,-5.0,0.5,0.5,label);
  67.  
  68.       if (right && !lc) return;
  69.       if (!right && !lb) return;
  70.  
  71.       if (ll) tick1 = 1.0;
  72.       if (lt) fxdtik(vmin,vmax,&tick1,&nsub1,&mode,&prec);
  73.  
  74.       if ( (li && !right) || (!li && right) ) {
  75.         minor = -minor;
  76.         major = -major;
  77.       }  
  78.  
  79.       gwm(&xscl,&xoff,&yscl,&yoff);
  80.       dxm = dx * xscl;
  81.       dym = dy * yscl;
  82.       diag = sqrt(dxm*dxm + dym*dym);
  83.  
  84.       xminor = minor * dxm/diag;
  85.       xmajor = major * dxm/diag;
  86.       yminor = minor * dym/diag;
  87.       ymajor = major * dym/diag;
  88.  
  89. /* Draw the line */
  90.  
  91.       movwor(wx,wy1);
  92.       if (lt) {
  93.         tp=tick1*floor(vmin/tick1);
  94. lab2:
  95.         tn=tp+tick1;
  96.         if (ls) {
  97.           if (ll) {
  98.             for (i=0; i <= 7; i++) {
  99.               temp=tp+xlog[i];
  100.               if (betw(temp,vmin,vmax)) {
  101.                 lambda = (temp-vmin)/(vmax-vmin);
  102.                 fxstik(wcmmx(wx),wcmmy(wy1+lambda*dwy),xminor,yminor);
  103.               }
  104.             }
  105.           }
  106.           else  {
  107.             for (i=1; i<= nsub1-1; i++)  {
  108.               temp=tp+i*(tn-tp)/nsub1;
  109.               if (betw(temp,vmin,vmax)) {
  110.                 lambda = (temp-vmin)/(vmax-vmin);
  111.                 fxstik(wcmmx(wx),wcmmy(wy1+lambda*dwy),xminor,yminor);
  112.               }
  113.             }
  114.           }
  115.         }
  116.         temp=tn;
  117.         if (betw(temp,vmin,vmax)) {
  118.           lambda = (temp-vmin)/(vmax-vmin);
  119.           fxstik(wcmmx(wx),wcmmy(wy1+lambda*dwy),xmajor,ymajor);
  120.           tp=tn;
  121.           goto lab2;
  122.         }
  123.       }
  124.  
  125.       drawor(wx,wy2);
  126.  
  127. /* Label the line */
  128.  
  129.       if (ln && lt) {
  130.         tp=tick1*floor(vmin/tick1);
  131. lab82:
  132.         tn=tp+tick1;
  133.         if (betw(tn,vmin,vmax)) {
  134.           if (!ll) 
  135.             fxform(tn,mode,prec,string);
  136.           else
  137.             sprintf(string,"10\\u%d",round(tn));
  138.           pos=(tn-vmin)/(vmax-vmin);
  139.           if (ln && !right) fxztx("v",dx,dy,wx,wy1,wy2,0.5,pos,1.0,string);
  140.           if (lm && right) fxztx("v",dx,dy,wx,wy1,wy2,-0.5,pos,0.0,string);
  141.           tp=tn;
  142.           goto lab82;
  143.         }
  144.       }
  145. }
  146.